package com.sc.nft.dao;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.CollectionSimpleVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.BoxProduct;
import com.sc.nft.mapper.BoxProductMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_box_product)数据DAO
 *
 * @author Sun
 * @since 2022-05-30 17:30:36
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class BoxProductDao extends ServiceImpl<BoxProductMapper, BoxProduct> {

    public BoxProduct getByTitle(String title) {
        return new LambdaQueryChainWrapper<BoxProduct>(baseMapper).eq(BoxProduct::getFirstTitle,title).one();
    }

    public Page<BoxProduct> getPage(String firstTitle, Boolean status, int pageNo, int pageSize){
        LambdaQueryWrapper<BoxProduct> wrapper= new LambdaQueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(firstTitle),BoxProduct::getFirstTitle,firstTitle);
        wrapper.eq(status!=null,BoxProduct::getStatus,status);
        wrapper.orderByDesc(BoxProduct::getId);
        return page(new Page<>(pageNo,pageSize),wrapper);
    }


    public List<BoxProduct> getCollectionSimpleVO(String firstTitle) {
        LambdaQueryWrapper<BoxProduct> wrapper= new LambdaQueryWrapper<>();
        wrapper.eq(BoxProduct::getStatus,true);
        wrapper.like(StrUtil.isNotBlank(firstTitle),BoxProduct::getFirstTitle,firstTitle);
        return list(wrapper);
    }

}